package com.zhongjian.technologycal.mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.bean.AddressBean;

import java.util.List;

/**
 * Created by wei on 2018/1/17.
 */

public class AddressListAdaper extends BaseAdapter {

    private Context context;
    private List<AddressBean> listItems;
    private LayoutInflater listContainer;

    public final class ListItemView {
        public TextView address_list_tv_name;
        public TextView address_list_tv_phone;
        public TextView address_list_tv_details;

    }

    public AddressListAdaper(Context context, List<AddressBean> listItems) {
        this.context = context;
        listContainer = LayoutInflater.from(context);
        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            listItemView = new ListItemView();
            convertView = listContainer.inflate(R.layout.items_contact_select_recyclerview,
                    null);

            listItemView.address_list_tv_name = (TextView) convertView
                    .findViewById(R.id.address_list_tv_name);
            listItemView.address_list_tv_phone = (TextView) convertView
                    .findViewById(R.id.address_list_tv_phone);
            listItemView.address_list_tv_details = (TextView) convertView
                    .findViewById(R.id.address_list_tv_details);

            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }
          //将数据填充到具体的view中
        listItemView.address_list_tv_name.setText(listItems.get(position).getData().get(position).getName());

        listItemView.address_list_tv_phone.setText("" + listItems.get(position).getData().get(position).getPhone());

        listItemView.address_list_tv_details.setText("" +
                listItems.get(position).getData().get(position).getProvinceName()+
                listItems.get(position).getData().get(position).getCityName()+
                listItems.get(position).getData().get(position).getRegionName()+
                listItems.get(position).getData().get(position).getDetailAddress());

        return convertView;
    }


}
